package com.yfq;


import com.yfq.springframework.beans.*;
import com.yfq.springframework.beans.factory.BeanFactory;
import com.yfq.springframework.context.ApplicationContext;
import com.yfq.springframework.context.ApplicationContextAware;

/**
 * @author 姚凤桥
 * @date 2022/11/22 16:25
 * @description
 */
public class UserService implements InitializingBean, DisposableBean, BeanNameAware, BeanFactoryAware, BeanClassLoaderAware, ApplicationContextAware {
    private String username;

    private UserDao userDao;

    private String beanName;

    private BeanFactory beanFactory;

    private ClassLoader classLoader;

    private ApplicationContext applicationContext;

    public UserService() {
    }

    public UserService(String username) {
        this.username = username;
    }

    public void sayHello(String id) {
        System.out.println("hello " + username + "..." + userDao.getUserName(id));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean初始化方法执行...");
    }

    public void init() {
        System.out.println("xml配置初始化方法执行...");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean销毁方法执行...");
    }

    public void close() {
        System.out.println("xml配置的销毁方法执行...");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public String getUsername() {
        return username;
    }

    public String getBeanName() {
        return beanName;
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }

    public ClassLoader getClassLoader() {
        return classLoader;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
